RFID READER MODULE
Pin Description
/* Name : main.c * Purpose : Source code for RFID Interfacing with AT89C52. * Author : Gemicates * Date : 2017-06-21 * Website : www.gemicates.org * Revision : None */ #include <regx52.h> #include <stdio.h> #include <string.h> #define lcd P2 // LCD data pins sbit rs=P1^0; // register select pin sbit rw=P1^1; // read write pin sbit e=P1^2; // enable pin unsigned char card_id[4]; // ID varialble decleration // DELAY FUNCTIONS void delay (unsigned int); // LCD FUNCTIONS void lcddata(char t); // lcd functions void lcdstring( char *l); void lcdcmd(unsigned char); void com(); // RECEIVE FUNCTIONS void init(); unsigned char* receive(); // MAIN FUNCTION void main() { unsigned char i,j,k,n; unsigned char d[12]; unsigned char C[12]; unsigned char c1[12]={0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31}; P1=0x00; P2=0x00; init(); com(); delay(100); lcdstring("ID : "); delay(100); for(i=0;i<12;i++) // ID value receive function { while(RI==0); card_id[i]=SBUF; d[i]=card_id[i]; RI=0; } for(n=0;n<12;n++) { C[n]=d[n]; lcddata(C[n]); } lcdcmd(0xc0); k=0; for(i=0;i<12;i++) { for(j=0;j<12;j++) { if (c1[i]==d[j]) { k=k+1; } else { k=0; } } } if (k>1) { lcdstring("USER VERIFIED"); delay(500); lcdcmd(0xc0); } else if (k==0) { lcdstring("INVALID USER"); delay(500); lcdcmd(0xc0); } } void init() // UART initialization { TMOD=0x20; TH1=0xFD; SCON=0x50; TR1=1; } void delay(unsigned int msec ) // The delay function provides delay in msec. { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275; j++); } void lcddata(char t) // lcd data function { rs=1; lcd=t; rw=0; e=1; delay(1); e=0; } void lcdcmd(unsigned char c) // lcd command function { lcd=c; rs=0; rw=0; e=1; delay(1); e=0; } void com() // lcd initialization function { lcdcmd(0x38); delay(10); lcdcmd(0x0c); delay(10); lcdcmd(0x01); delay(10); } void lcdstring(char *d) // lcd string print function { while(*d !=0) { lcddata(*d++); } }